package com.lp.biz.operations.controller;

import com.lp.biz.operations.model.query.HomeRecommendQuery;
import com.lp.biz.operations.model.query.RecommendContentQuery;
import com.lp.biz.operations.model.vo.HomeRecommendItemAddVo;
import com.lp.biz.operations.model.vo.HomeRecommendSetting;
import com.lp.biz.operations.model.vo.HomeRecommendVo;
import com.lp.biz.operations.model.vo.RecommendSort;
import com.lp.biz.operations.service.RecommendService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.entity.PageParams;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.MenuConstant.*;

/**
 * @program: backend
 * @description:
 * @author: Ke.Song
 * @since: 2024-07-13 1:02:11
 */
@RestController
@RequestMapping("/recommend")
public class RecommendController {

    @Autowired
    private RecommendService recommendService;

    /**
     * 获取首页推荐位
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult getHomeRecommend(HomeRecommendQuery query) {
        return recommendService.getHomeRecommend(query);
    }

    /**
     * 首页推荐位排序
     * @param recommendSort 排序
     * @return 处理结果
     */
    @PutMapping("/sort")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult updateSort(@RequestBody @Validated RecommendSort recommendSort) {
        recommendService.updateSort(recommendSort);
        return CommonResult.success();
    }

    /**
     * 更新推荐位状态
     * @param recommendId 推荐位id
     * @return 处理结果
     */
    @PutMapping("/{recommendId}/display")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult updateRecommendStatus(@PathVariable Integer recommendId) {
        recommendService.updateRecommendStatus(recommendId);
        return CommonResult.success();
    }

    /**
     * 删除推荐位
     * @param recommendId 推荐位id
     * @return 查询结果
     */
    @DeleteMapping("/{recommendId}")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult deleteRecommend(@PathVariable Integer recommendId) {
        recommendService.deleteRecommend(recommendId);
        return CommonResult.success();
    }

    /**
     * 创建/更新推荐位
     * @param params 推荐位参数
     * @return 处理结果
     */
    @PostMapping("")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult addOrUpdateRecommend(@RequestBody@Validated HomeRecommendVo params) {
        recommendService.addOrUpdateRecommend(params);
        return CommonResult.success();
    }

    /**
     * 获取首页推荐位详情
     * @param recommendId 推荐位id
     * @return 查询结果
     */
    @GetMapping("/{recommendId}")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult getRecommend(@PathVariable Integer recommendId) {
        return recommendService.getRecommend(recommendId);
    }

    /**
     * 获取首页推荐位明细列表
     * @param recommendId 首页推荐位id
     * @return 查询结果
     */
    @GetMapping("/{recommendId}/items")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult getRecommendItems(@PathVariable Integer recommendId, PageParams query) {
        return recommendService.getRecommendItems(recommendId, query);
    }

    /**
     * 更新首页推荐位设置
     * @param recommendId 推荐位id
     * @param setting 设置参数
     * @return 处理结果
     */
    @PutMapping("/{recommendId}/setting")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult updateRecommendSetting(@PathVariable Integer recommendId, @RequestBody@Validated HomeRecommendSetting setting) {
        recommendService.updateRecommendSetting(recommendId, setting);
        return CommonResult.success();
    }

    /**
     * 获取共读会/训练营/故事内容库
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/content")
    @PermissionAnnotation(menus = {HOME_RECOMMEND, BANNER, TODAY})
    public CommonResult getRecommendContentList(RecommendContentQuery query) {
        return recommendService.getRecommendContentList(query);
    }

    /**
     * 获取名人名言内容库
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/text")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult getRecommendTextList(RecommendContentQuery query) {
        return recommendService.getRecommendTextList(query);
    }

    /**
     * 添加首页推荐位明细 - 共读会/故事/训练营
     * @param vo 添加参数
     * @return 处理结果
     */
    @PostMapping("/{recommendId}/items")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult addRecommendItem(@RequestBody @Validated HomeRecommendItemAddVo vo, @PathVariable Integer recommendId) {
        vo.setRecommendId(recommendId);
        recommendService.addRecommendItem(vo);
        return CommonResult.success();
    }

    /**
     * 删除推荐位明细
     * @param itemId 明细id
     * @return 处理结果
     */
    @DeleteMapping("/items/{itemId}")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult deleteRecommendItem(@PathVariable Integer itemId) {
        recommendService.deleteRecommendItem(itemId);
        return CommonResult.success();
    }

    /**
     * 添加首页推荐位明细 - 名人名言
     * @param vo 添加参数
     * @return 处理结果
     */
    @PostMapping("/{recommendId}/items/text")
    @PermissionAnnotation(menus = {HOME_RECOMMEND})
    public CommonResult addRecommendTextItem(@RequestBody @Validated HomeRecommendItemAddVo vo, @PathVariable Integer recommendId) {
        vo.setRecommendId(recommendId);
        recommendService.addRecommendTextItem(vo);
        return CommonResult.success();
    }
}
